'RECURSOS
$RESOURCE MAIN_ICO AS ".\main.ico"
$RESOURCE FACTURACION_ICO AS ".\facturacion.ico"
$RESOURCE CLIENTES_ICO AS ".\clientes.ico"
$RESOURCE ACERCADE_ICO AS ".\acercade.ico"
$RESOURCE CONECT_ICO AS ".\conect.ico"
$RESOURCE LEYENDA_ICO AS ".\leyenda.ico"

' UDT's

TYPE DbConnect
	User AS STRING * 20
	Passwd AS STRING * 20
	Host AS STRING * 30
	DbName AS STRING * 20
END TYPE


'VARIABLES

DIM MySQL AS QMYSQL
DIM miDB AS DbConnect
DIM QueryString AS STRING
DIM dbFile AS QFILESTREAM
DIM Host AS STRING
DIM DbName AS STRING
DIM User AS STRING
DIM Passwd AS STRING
DIM Total AS DOUBLE
DIM Codigo AS STRING

CREATE Font AS QFont
    Color = &HFF0000
    Name = "Arial"
    Size = 12
END CREATE



' FUNCIONES

SUB MySQL2Grid(SubMySQL AS QMYSQL, Grid AS QSTRINGGRID, Query AS STRING)
	IF SubMySQL.Query(Query) = 0 THEN
		MessageDLG("Imposible conectar DB", mtError, mbOk, 0)
		EXIT SUB
	END IF
	
	DEFINT I
	DEFINT J

	I = 0
	J = 0
	
	Grid.RowCount = SubMySQL.RowCount + 1

	J = 1

	WHILE SubMySQL.FetchRow     
		SubMySQL.FieldSeek(0) 
		FOR I = 0 TO SubMySQL.FieldCount - 1
			Grid.Cell(I,J) = LTRIM$(RTRIM$(SubMySQL.Row(I)))
		NEXT
		J++
	WEND
END SUB

SUB MySQL2ComboBox(SubMySQL AS QMYSQL, ComboBox AS QCOMBOBOX, Query AS STRING)
	IF SubMySQL.Query(Query) = 0 THEN
		MessageDLG("Imposible conectar DB", mtError, mbOk, 0)
		EXIT SUB
	END IF
	
	DEFINT I
	I = 0

	WHILE SubMySQL.FetchRow     
		SubMySQL.FieldSeek(0) 
		FOR I = 0 TO SubMySQL.FieldCount - 1
			ComboBox.AddItems LTRIM$(RTRIM$(SubMySQL.Row(I)))
		NEXT
	WEND
END SUB

SUB MySQL2Edit(SubMySQL AS QMYSQL, Edit AS QEDIT, Query AS STRING)
	IF SubMySQL.Query(Query) = 0 THEN
		MessageDLG("Imposible conectar DB", mtError, mbOk, 0)
		EXIT SUB
	END IF
	
	DEFINT I
	I = 0

	WHILE SubMySQL.FetchRow     
		SubMySQL.FieldSeek(0) 
		FOR I = 0 TO SubMySQL.FieldCount - 1
			Edit.Text = LTRIM$(RTRIM$(SubMySQL.Row(I)))
		NEXT
	WEND
END SUB

'INICIALIZACION

IF dbFile.Open("conndata.dat", fmOpenRead) = FALSE THEN
	miDB.User = ""
	miDb.Passwd = ""
	miDb.Host = ""
	miDb.DbName = ""
	MessageDLG("CONFIGURE EL ACCESO A BASE DE DATOS!", mtWarning, mbOk, 0)
ELSE
	dbFile.ReadUDT(miDB)
	dbFile.Close
	
	Host = ltrim$(rtrim$(miDB.Host))
	DbName = ltrim$(rtrim$(miDB.DbName))
	User = ltrim$(rtrim$(miDB.User))
	Passwd = ltrim$(rtrim$(miDB.Passwd))
	
	MySQL.Connect(Host, User, Passwd)

	IF MySQL.Connected THEN
		MySQL.SelectDB(DbName)
	ELSE
		MessageDLG("Error al Conectarse a " + Host, mtError, mbOk, 0)
	END IF

END IF

Printer.Font = Font

